package cn.zero.basic.service.impl;

import cn.zero.basic.mapper.BaseMapper;
import cn.zero.basic.query.BaseQuery;
import cn.zero.basic.service.IBaseService;
import cn.zero.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @Description: TODO
 * @Author: Tang
 * @Version: 1.0
 * @Date:  2022/6/21 16:54
 */

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    /**
     * @Title: loadAll
     * @Description: TODO
     * @Author: Tang
     * @Version: 1.0
     * @Date:  2022/6/21 16:55
     * @Parameters: []
     * @Return java.util.List<cn.zero.org.domain.Base>
     */
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    /**
     * @Title: loadById
     * @Description: TODO
     * @Author: Tang
     * @Version: 1.0
     * @Date:  2022/6/21 16:55
     * @Parameters: [java.lang.Long]
     * @Return cn.zero.org.domain.Base
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /**
     * @Title: remove
     * @Description: TODO
     * @Author: Tang
     * @Version: 1.0
     * @Date:  2022/6/21 16:55
     * @Parameters: [java.lang.Long]
     * @Return void
     */
    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    /**
     * @Title: save
     * @Description: TODO
     * @Author: Tang
     * @Version: 1.0
     * @Date:  2022/6/21 16:55
     * @Parameters: [cn.zero.org.domain.Base]
     * @Return void
     */
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);

    }
    /**
     * @Title: update
     * @Description: TODO
     * @Author: Tang
     * @Version: 1.0
     * @Date:  2022/6/21 16:55
     * @Parameters: [cn.zero.org.domain.Base]
     * @Return void
     */
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    /**
     * @Title: queryData
     * @Description: TODO
     * @Author: Tang
     * @Version: 1.0
     * @Date:  2022/6/21 16:55
     * @Parameters: [cn.zero.org.query.BaseQuery]
     * @Return cn.zero.basic.utils.PageList<cn.zero.org.domain.Base>
     */
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {
        //当前页面总条数
        Integer total = baseMapper.queryCount(baseQuery);
        //当前页面数据
        List<T> rows = baseMapper.queryData(baseQuery);
        return new PageList<T>(total,rows);
    }

    /**
     * @Title: batchDel
     * @Description: TODO
     * @Author: Tang
     * @Version: 1.0
     * @Date:  2022/6/26 9:25  
     * @Parameters: [java.lang.Long[]]
     * @Return void
     */
    @Override
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);
    }

}
